﻿@model BusinessesListViewModel
@{
    ViewBag.Title = "Businesses";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}
@section Styles
{
    <link href="@Url.Content("~/Areas/Admin/Content/zatify/Css/pop_ups.css")" rel="stylesheet" type="text/css" />
}
@section Scripts
{
    <script src="@Url.Content("~/Areas/Admin/Scripts/pop_ups.js")" type="text/javascript"></script>
    <script type="text/javascript">

        function getCheckedBusinessesIds() {
            var selectedBusinessesIds = new Array();

            $("#businessesList input[type=checkbox]:checked").each(function () {

                selectedBusinessesIds.push($(this).val());
            });

            return selectedBusinessesIds;
        }

        function deleteBusinesses() {

            var checkedBusinessesIds = getCheckedBusinessesIds();
            
            if(checkedBusinessesIds && checkedBusinessesIds.length > 0)
            {
                if (confirm('Are you sure you want to delete selected businesses?')) {

                    var data = { businessesIds: checkedBusinessesIds };

                    $.ajax({
                        url: "@Url.Action("DeleteBusinesses", "Business")",
                        type: 'POST',
                        data: data,
                        traditional: true,
                        success: function (result) {

                            if(result){

                                $("#formPages").submit();
                                //window.location.reload()
                            }
                            else{

                                alert("Error occured during operation.");
                            }
                        }
                    });
                }
            }
            else
            {
                alert("Check businesses to delete.");
            }
         }

         function activateBusinesses(activate)
         {
            var checkedBusinessesIds = getCheckedBusinessesIds();
            
            if(checkedBusinessesIds && checkedBusinessesIds.length > 0)
            {
                if (confirm('Are you sure you want to change statuses of selected businesses?')) {
            
                    var data = { businessesIds: checkedBusinessesIds, activate: activate };

                    $.ajax({
                        url: "@Url.Action("ChangeBusinessesStatus", "Business")",
                        type: 'POST',
                        data: data,
                        traditional: true,
                        success: function (result) {

                           if(result){

                                $("#formPages").submit();
                                //window.location.reload()
                            }
                            else{

                                alert("Error occured during operation.");
                            }
                        }
                    });
                }
            }
            else
            {
                alert("Check businesses to change status.");
            }
         }
    </script>
}
<!--starts search results-->
<div class="search_result_bd">
    <div id="businessesList" class="zatify_table_content">
        @*@Html.Partial("Partials/UsersListControl", Model)*@
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                {
                    <th width="4%">
                        &nbsp;
                    </th>
               
                    <th width="10%">
                        Action
                    </th>
                }
                <th width="11%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.BusinessNameSortParam })">Business Name</a>
                </th>
                <th width="11%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.PromoStatusSortParam })">Promo status</a>                    
                </th>
                <th width="8%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.UserIDSortParam })">User ID</a>
                </th>
                <th width="15%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.EmailSortParam })">Email</a>
                </th>
                <th width="6%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.WebSortParam })">Web</a>
                </th>
                <th width="6%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.BusinessPhoneSortParam })">Business Phone</a>
                </th>
                <th width="6%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.CellPhoneSortParam })">Cell Phone</a>
                </th>
                <th width="4%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.StatusSortParam })">Status</a>
                </th>
                <th width="5%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.FaxSortParam })">Fax</a>
                </th>
                <th width="7%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.TollFreeSortParam })">Toll Free</a>
                </th>
                <th width="7%">
                    Address
                </th>
                <th width="5%">
                    City
                </th>
                <th width="3%">
                    State
                </th>
                <th width="3%">
                    Zip
                </th>
                <th width="7%">
                    <a href="@Url.Action("List", new { sortOrder = @Model.RegDateSortParam })">Reg. Date</a>
                </th>
            </tr>
            @foreach (var business in Model.Businesses)
            {
                <tr>
                    @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                    {
                        <td>
                            <input name="" value="@business.BusinessId" type="checkbox" />
                        </td>
                    
                        <td>
                            <a href="@Url.Action("Delete", new { id = business.BusinessId })" title="Delete" onclick="return confirm('Are you sure you want to delete this business?');">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/delete_icon.gif")" alt="Delete" />
                            </a>
                            @if (business.IsActive)
                            {
                                <a href="@Url.Action("ChangeBusinessStatus", new { page = 1, id = business.BusinessId, activate = 0 })" title="Inactivate" onclick="return confirm('Are you sure you want to Inactivate this business?');">
                                    <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/active_icon.png")" alt="Inactivate" />
                                </a>
                            }
                            else
                            {
                                <a href="@Url.Action("ChangeBusinessStatus", new { page = 1, id = business.BusinessId, activate = 1 })" title="Activate" onclick="return confirm('Are you sure you want to Activate this business?');">
                                    <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/suspend_icon.png")" alt="Activate" />
                                </a>
                            }
                            <a href="#" title="Change password" onclick="changePassword(@business.BusinessId)">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/password_icon.png")" alt="Change password" />
                            </a>
                        </td>
                    }
                    <td>
                        <a href="@Url.Action("GeneralInfo", "Business", new { id = @business.BusinessId })")>
                            @business.BusinessName
                        </a>
                    </td>
                    <td>
                        @business.PromoStatus
                    </td>
                    <td>
                        @business.Login
                    </td>
                    <td>
                        @business.Email
                    </td>
                    <td>
                        @business.Web
                    </td>
                    <td>
                        @business.BusinessPhone
                    </td>
                    <td>
                        @business.CellPhone
                    </td>
                    <td>
                        @(business.IsActive ? "Active" : "Inactive")
                    </td>
                    <td>
                        @business.Fax
                    </td>
                    <td>
                        @business.TollFreePhone
                    </td>
                    <td>
                        @business.StreetAddress1
                    </td>
                    <td>
                        @business.City
                    </td>
                    <td>
                        @business.StateCode
                    </td>
                    <td>
                        @business.ZipCode
                    </td>
                    <td>
                        @business.DateAdded.ToShortDateString()
                    </td>
                </tr>
            }
        </table>
    </div>
</div>
<div class="clearfix">
</div>
<!--end search results-->
<!--start pagination-->
<div class="zatify_pagination">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="24%">
                <table>
                    <tr>
                        @Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new
                   {
                       page = x,
                       sortOrder = Model.SortOrder
                   }),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_first_btn.png"),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_last_btn.png"),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_back.png"),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_next.png"))
                    </tr>
                </table>
            </td>
            <td width="6%">
                Page No:
            </td>
            <td width="30%">
                @using (Html.BeginForm("List", "Business", FormMethod.Post, new { id = "formPages" }))
                {
                    @Html.DropDownList("page", (IEnumerable<SelectListItem>)ViewData["pagesCount"], new { onchange = "$('#formPages').submit();", @class = "select_box" })
                }
            </td>
            <td width="2%">
                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/excel_icon.png")" alt="" title="back" border="0" />
            </td>
            <td class="pagination_no" width="20%">
                <a href="@Url.Action("BusinessesReport", "ExcelReports")">Export to Excel</a>
            </td>
            <td width="18%">
                <span class="page_no_info">@Model.PagingInfo.TotalItems items in @Model.PagingInfo.TotalPages
                    pages</span>
            </td>
        </tr>
    </table>
</div>
<div class="clearfix">
</div>
<!--end pagination-->
@if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
{
    <!--start button-->
    <div class="zatify_panel_btn">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <input name="" type="submit" class="btn apps_btn apps_gray_btn" value="Delete Selected"
                        onclick="deleteBusinesses()" />
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Suspend Selected"
                        onclick="activateBusinesses(0)" />
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Activate Selected"
                        onclick="activateBusinesses(1)" />
                    <a href="@Url.Action("GeneralInfo", "Business")">
                        <input style="margin-left: 200px;" name="" type="button" class="btn apps_btn apps_gray_btn"
                            value="Add New" /></a>
                </td>
            </tr>
        </table>
        <div class="clearfix">
        </div>
    </div>
    <!--end button-->
    <!-- START POP-UPs -->
    <div id="overlay" class="web_dialog_overlay">
    </div>
@*@Html.Partial("Partials/NewUserControl", new Zatify.WebUI.Admin.Models.AddNewUserViewModel())*@
    @Html.Partial("Partials/ChangeBusinessPasswordControl", new Zatify.WebUI.Admin.Models.ChangeBusinessPasswordViewModel())
    <!-- END POP-UPs -->
}